package com.ninong.ker.common.tools;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

import java.text.ParseException;
import java.util.Date;

/**
 * 日期工具类
 * 
 * @author anker_cheng
 * @dOct 15, 20177:44:48 PM
 */
public final class MyDateUtils {

	/** 日期格式化PATTERN */
	public static interface DatePattern {
		String PATTERN_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
		String PURE_DATETIME_PATTERN = "yyyyMMdd";
		String PATTERN_DATE = "yyyy-MM-dd";
		String PATTERN_YEAR_MONTH = "yyyy-MM";
		String PATTERN_DATE_C = "yyyy年MM月dd日";
		String PATTERN_DATE_C_M = "yyyy年MM月dd日 HH:mm";
		String PATTERN_MONTH_C_M = "MM月dd日 HH:mm";
		String PATTERN_DATE_C_M_POINT = "yyyy.MM.dd HH:mm";
		String PATTERN_TIME = "HH:mm:ss";
		String PATTERN_MINUTE = "HH:mm";
		String PATTERN_DATE_TIMETZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

	}

	/** 私有构造 */
	private MyDateUtils() {
	}

	public static Date parseDate(String src, String... patterns) {
		if(src == null || src.length() == 0) {
			return null;
		}
		try {
			return DateUtils.parseDate(src, patterns);
		} catch (ParseException e) {
			return null;
		}
	}

	public static String format(Date date, String pattern) {
		return DateFormatUtils.format(date, pattern);
	}
}